package com.nanbei.a04;

import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor;
import org.springframework.context.annotation.CommonAnnotationBeanPostProcessor;
import org.springframework.context.annotation.ContextAnnotationAutowireCandidateResolver;
import org.springframework.context.support.GenericApplicationContext;

/**
 * @ClassDescription:  bean的后置处理器
 * @JdkVersion: 1.8
 * @Author: libs
 * @Created: 2024/9/10 17:03
 */
public class A04Application {
    public static void main(String[] args) {
        //Generic 通用的
        // GenericApplicationContext 是一个【干净】的容器   内部未添加 bean工厂处理器 和 bean处理器
        GenericApplicationContext context = new GenericApplicationContext();
        context.registerBean("bean1",Bean1.class);
        context.registerBean("bean2",Bean2.class);
        context.registerBean("bean3",Bean3.class);
        context.registerBean("bean4",Bean4.class);

        context.getDefaultListableBeanFactory().setAutowireCandidateResolver(new ContextAnnotationAutowireCandidateResolver());
        context.registerBean(AutowiredAnnotationBeanPostProcessor.class);  //@Autowired @Value
        context.registerBean(CommonAnnotationBeanPostProcessor.class); // @Resource   @PostConstruct   @PreDestroy
        ConfigurationPropertiesBindingPostProcessor.register(context.getDefaultListableBeanFactory()); // @ConfigurationProperties


        context.refresh();
        System.out.println(context.getBean(Bean4.class));
        context.close();
    }
}
